<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Punch_alterations extends CI_Controller
{
	function __construct()
	{
		parent::__construct();		
		if (!$this->tank_auth->is_logged_in()) redirect('auth/login');				
		
		//load models
		$this->load->model('Punch_alterations_db');
	}
	
	// /*VIEW FUNCTIONS*/
	// function index()
	// {	
		// redirect('punch_alterations/manage');
	// }
	// function add()
	// {
		// //default
		// $data['ptitle'] = "Add Punch";				
		// $data['username'] = $this->tank_auth->get_username();
		// $data['module'] = 'punch_alterations';
		// $data['active_header'] = 'admin';
		// //end default
		
		// //dropdowns
		// //$data['groups'] = $this->Punch_alterations_db->getPunch_alterations();
		
		// $data['content'] = $this->load->view('add',$data,true);		
		// $this->load->view('default_view',$data);
	// }
	
	// function manage()
	// {
		// //default
		// $data['ptitle'] = "Manage Punch_alterations";				
		// $data['username'] = $this->tank_auth->get_username();
		// $data['module'] = 'punch_alterations';
		// $data['active_header'] = 'admin';
		// //end default		
		
		// $data['content'] = $this->load->view('manage',$data,true);		
		// $this->load->view('default_view',$data);
	// }
	
	// function edit($id)
	// {		
		// //default
		// $data['ptitle'] = "Edit Punch";				
		// $data['username'] = $this->tank_auth->get_username();
		// $data['module'] = 'punch_alterations';
		// $data['active_header'] = 'admin';
		// //end default
		
		// //dropdowns
		// //$data['groups'] = $this->Punch_alterations_db->getPunch_alterations(array("group_id != "=>$id));
		
		// //check punch if existing
		// $emp = $this->Punch_alterations_db->getPunch_alterations(array('punch_id'=>$id));
		// if(!count($emp)) show_404('page');
		
		// $data['item'] = $id;
		// $data['content'] = $this->load->view('edit',$data,true);		
		// $this->load->view('default_view',$data);
	// }
	// /*END VIEW FUNCTIONS*/
	
	
	/* AJAX FUNCTIONS */
	function addItem()
	{
		$dt = null;
		$error = false;
		foreach($_POST as $name => $value) {
			if (isset($_POST[$name])) $dt[$name] = $this->input->post($name);
		}
		$dt['punchdate'] = date('Y-m-d H:i:s',$dt['punchdate']);
		
		//set additional data
		$now = date('Y-m-d H:i:s');
		$dt['created'] = $now;
		$dt['user_id'] = $this->tank_auth->get_user_id();
		$dt['created_by'] = $dt['modified_by'] = $this->tank_auth->get_user_id();		
		
		$item = $this->Punch_alterations_db->save($dt);
		
		//audit trail
		$this->Audittrail_db->save(array('module'=>'punch_alterations', 'item_id'=>$item, 'action'=>'add', 'description'=>serialize($dt), 'created'=>$now, 'created_by'=>$this->tank_auth->get_user_id()));
		
		echo json_encode(array('return'=>'success'));
		return;
	}
	
	// function viewItem()
	// {
		// $dt['punch_id'] = $this->input->post('item');
		// $details = $this->Punch_alterations_db->getPunch_alterations($dt);
		// if ($details)
		// {
			// //$details[0]['date_hired'] = ($details[0]['date_hired']) ? $this->members_pi->convertDateDisplay($details[0]['date_hired'],false,'') : '';					
			// echo json_encode($details);
		// }
	// }
	
	function updateItem()
	{	
		$id = $this->input->post('item');		
		$dt = null;
		$error = false;
		foreach($_POST as $name => $value) {
			if($name!='item')
				if (isset($_POST[$name])) $dt[$name] = $this->input->post($name);
		}		
					
		//set additional data
		$dt['modified'] = date('Y-m-d H:i:s');
		$dt['modified_by'] = $this->tank_auth->get_user_id();		
		$item = $this->Punch_alterations_db->save($dt, $id);
		
		
		//audit trail
		$this->Audittrail_db->save(array('module'=>'punch_alterations', 'item_id'=>$item, 'action'=>'update', 'description'=>serialize($dt), 'created'=>$dt['modified'], 'created_by'=>$this->tank_auth->get_user_id()));
		
		echo json_encode(array('return'=>'success'));
		return;
	}
	
	// function deleteItem()
	// {
		// $dt = $this->input->post('items');
		
		// $item = $this->Punch_alterations_db->delete($dt);
		
		// //audit trail
		// foreach($dt as $d)
			// $this->Audittrail_db->save(array('module'=>'punch_alterations', 'item_id'=>$d, 'action'=>'delete', 'description'=>serialize($dt), 'created'=>date('Y-m-d H:i:s'), 'created_by'=>$this->tank_auth->get_user_id()));
		
		// echo json_encode(array('return'=>'success'));
		// return;
	// }
	
	// function listview()
	// {
		// $data = $this->Punch_alterations_db->getList();
		// echo json_encode($data);
	// }
	// /* END AJAX FUNCTIONS */
	
	
	// /* LOAD MODULE JS */
	// function js() {
        // $this->load->view('js/script.js');
    // }
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */